package com.example.sorftware20220103.controller;

import com.example.sorftware20220103.entity.Bill;
import com.example.sorftware20220103.entity.GrilFriend;
import com.example.sorftware20220103.entity.MaleStu;
import com.example.sorftware20220103.entity.User;
import com.example.sorftware20220103.service.BillService;
import com.example.sorftware20220103.service.UserService;
import com.example.sorftware20220103.util.PageInfoTool;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@RestController返回的是对象实体类
@Controller//找到页面资源的
public class MyController {

    //@GetMapping
    //postMapping
    @RequestMapping("/hello")
    public MaleStu Helloword() {
        GrilFriend friend = new GrilFriend("张三", 19);
        MaleStu stu = new MaleStu("李四", "英语", friend);
        return stu;
    }

    @GetMapping("/hello1")   //@RestController
    @ResponseBody
    public MaleStu Helloword1() {
        GrilFriend friend = new GrilFriend("张三", 19);
        MaleStu stu = new MaleStu("李四", "英语", friend);
        return stu;
    }


    @GetMapping("/page/{pageNum}")   //@RestController
    @ResponseBody
    public PageInfo getuserList(@PathVariable("pageNum") int pagenum,
                                Bill b) {

        return PageInfoTool.setPageInfo(billService, b, pagenum);
    }

    @Autowired
    PageInfoTool pageInfoTool;

    @Autowired
    UserService userservice;
    @Autowired
    RedisTemplate redisTemplate;

    //得到用户列表
    @GetMapping({"/list"})
    public String gotoListPage(@RequestParam(value = "pageNum",
            required = false, defaultValue = "1") Integer pagenum,
                               User u,
                               Model model) {
        pageInfoTool.setPageInfo(userservice, u, pagenum, model);
        return "list";
    }

    @Autowired
    BillService billService;


    //得到账单列表列表
    @GetMapping("/billList")   //@RestController
    public String getBillList(@RequestParam(value = "pageNum",
            required = false, defaultValue = "1") Integer pagenum, Bill b, Model model) {
        pageInfoTool.setPageInfo(billService, b, pagenum, model);
        return "billlist";
    }


}
